﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace Microsoft.Samples.Office.UnifiedCommunications.Gadget.Events
{
    public sealed class GadgetEventManager 
    {
        private GadgetEventManager() { }

        public static readonly GadgetEventManager Instance = new GadgetEventManager();
        private EventHandlerList EventList = new EventHandlerList();

        private static object UnreadVoicemailEventKey = new object();
        private static object EWSConfiguredEventKey = new object();
        private static object Fav5ChangedEventKey = new object();
        private static object Top5ChangedEventKey = new object();
        private static object GadgetSignInEventKey = new object();
        private static object VoicemailEnabledEventKey = new object();
        private static object EWSUnauthorizedEventKey = new object();
        private static object MismatchedSipEventKey = new object();
        private static object OpenVoicemailWindowEventKey = new object();
        private static object Fav5ContactDetailsConfirmedEventKey = new object();
        private static object DesktopContactChangedEventKey = new object();
        private static object NotifyDesktopContactChangedEventKey = new object();
        private static object PresenceStatusChangedEventKey = new object();
        private static object ApplicationUnloadedEventKey = new object();

        #region UnreadVoicemailEvent
        public event EventHandler UnreadVoicemailEvent
        {
            add
            {
                EventList.RemoveHandler(UnreadVoicemailEventKey, value);
                EventList.AddHandler(UnreadVoicemailEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(UnreadVoicemailEventKey, value);
            }
        }

        public void OnUnreadVoicemailEvent(UnreadVoicemailEventArgs e)
        {
            if (EventList[UnreadVoicemailEventKey] != null)
            {
                ((EventHandler)EventList[UnreadVoicemailEventKey]).Invoke(this, e);
            }
        } 
        #endregion

        #region EWSConfiguredEvent
        public event EventHandler EWSConfiguredEvent
        {
            add
            {
                EventList.RemoveHandler(EWSConfiguredEventKey, value);
                EventList.AddHandler(EWSConfiguredEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(EWSConfiguredEventKey, value);
            }
        }

        public void OnEWSConfiguredEvent(EWSConfiguredEventArgs e)
        {
            if (EventList[EWSConfiguredEventKey] != null)
            {
                ((EventHandler)EventList[EWSConfiguredEventKey]).Invoke(this, e);
            }
        } 
        #endregion

        #region Fav5ChangedEvent
        public event EventHandler Fav5ChangedEvent
        {
            add
            {
                EventList.RemoveHandler(Fav5ChangedEventKey, value);
                EventList.AddHandler(Fav5ChangedEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(Fav5ChangedEventKey, value);
            }
        }

        public void OnFav5ChangedEvent(Fav5ChangedEventArgs e)
        {
            if (EventList[Fav5ChangedEventKey] != null)
            {
                ((EventHandler)EventList[Fav5ChangedEventKey]).Invoke(this, e);
            }
        } 
        #endregion

        #region Top5ChangedEvent
        public event EventHandler Top5ChangedEvent
        {
            add
            {
                EventList.RemoveHandler(Top5ChangedEventKey, value);
                EventList.AddHandler(Top5ChangedEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(Top5ChangedEventKey, value);
            }
        }

        public void OnTop5ChangedEvent(Top5ChangedEventArgs e)
        {
            if (EventList[Top5ChangedEventKey] != null)
            {
                ((EventHandler)EventList[Top5ChangedEventKey]).Invoke(this, e);
            }
        } 
        #endregion

        #region GadgetSignInEvent
        public event EventHandler GadgetSignInEvent
        {
            add
            {
                EventList.RemoveHandler(GadgetSignInEventKey, value);
                EventList.AddHandler(GadgetSignInEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(GadgetSignInEventKey, value);
            }
        }

        public void OnGadgetSignInEvent(GadgetSignInEventArgs e)
        {
            if (EventList[GadgetSignInEventKey] != null)
            {
                ((EventHandler)EventList[GadgetSignInEventKey]).Invoke(this, e);
            }
        } 
        #endregion

        #region VoicemailEnabledEvent
        public event EventHandler VoicemailEnabledEvent
        {
            add
            {
                EventList.RemoveHandler(VoicemailEnabledEventKey, value);
                EventList.AddHandler(VoicemailEnabledEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(VoicemailEnabledEventKey, value);
            }
        }

        public void OnVoicemailEnabledEvent(EventArgs e)
        {
            if (EventList[VoicemailEnabledEventKey] != null)
            {
                ((EventHandler)EventList[VoicemailEnabledEventKey]).Invoke(this, e);
            }
        } 
        #endregion

        #region EWSUnauthorizedEvent
        public event EventHandler EWSUnauthorizedEvent
        {
            add
            {
                EventList.RemoveHandler(EWSUnauthorizedEventKey, value);
                EventList.AddHandler(EWSUnauthorizedEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(EWSUnauthorizedEventKey, value);
            }
        }

        public void OnEWSUnauthorizedEvent(EventArgs e)
        {
            if (EventList[EWSUnauthorizedEventKey] != null)
            {
                ((EventHandler)EventList[EWSUnauthorizedEventKey]).Invoke(this, e);
            }
        }
        #endregion

        #region MismatchedSipEvent
        public event EventHandler MismatchedSipEvent
        {
            add
            {
                EventList.RemoveHandler(MismatchedSipEventKey, value);
                EventList.AddHandler(MismatchedSipEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(MismatchedSipEventKey, value);
            }
        }

        public void OnMismatchedSipEvent(MismatchedSIPEventArgs e)
        {
            if (EventList[MismatchedSipEventKey] != null)
            {
                ((EventHandler)EventList[MismatchedSipEventKey]).Invoke(this, e);
            }
        }
        #endregion

        #region OpenVoicemailWindowEvent
        public event EventHandler OpenVoicemailWindowEvent
        {
            add
            {
                EventList.RemoveHandler(OpenVoicemailWindowEventKey, value);
                EventList.AddHandler(OpenVoicemailWindowEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(OpenVoicemailWindowEventKey, value);
            }
        }

        public void OnOpenVoicemailWindowEvent(EventArgs e)
        {
            if (EventList[OpenVoicemailWindowEventKey] != null)
            {
                ((EventHandler)EventList[OpenVoicemailWindowEventKey]).Invoke(this, e);
            }
        }
        #endregion

        #region Fav5ContactDetailsConfirmedEvent
        public event EventHandler Fav5ContactDetailsConfirmedEvent
        {
            add
            {
                EventList.RemoveHandler(Fav5ContactDetailsConfirmedEventKey, value);
                EventList.AddHandler(Fav5ContactDetailsConfirmedEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(Fav5ContactDetailsConfirmedEventKey, value);
            }
        }

        public void OnFav5ContactDetailsConfirmedEvent(Fav5ChangedEventArgs e)
        {
            if (EventList[Fav5ContactDetailsConfirmedEventKey] != null)
            {
                ((EventHandler)EventList[Fav5ContactDetailsConfirmedEventKey]).Invoke(this, e);
            }
        }
        #endregion

        #region DesktopContactChangedEvent
        public event EventHandler DesktopContactChangedEvent
        {
            add
            {
                EventList.RemoveHandler(DesktopContactChangedEventKey, value);
                EventList.AddHandler(DesktopContactChangedEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(DesktopContactChangedEventKey, value);
            }
        }

        public void OnDesktopContactChangedEvent(DesktopContactChangedEventArgs e)
        {
            if (EventList[DesktopContactChangedEventKey] != null)
            {
                ((EventHandler)EventList[DesktopContactChangedEventKey]).Invoke(this, e);
            }
        }
        #endregion

        #region NotifyDesktopContactChangedEvent
        public event EventHandler NotifyDesktopContactChangedEvent
        {
            add
            {
                EventList.RemoveHandler(NotifyDesktopContactChangedEventKey, value);
                EventList.AddHandler(NotifyDesktopContactChangedEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(NotifyDesktopContactChangedEventKey, value);
            }
        }

        public void OnNotifyDesktopContactChangedEvent(DesktopContactChangedEventArgs e)
        {
            if (EventList[NotifyDesktopContactChangedEventKey] != null)
            {
                ((EventHandler)EventList[NotifyDesktopContactChangedEventKey]).Invoke(this, e);
            }
        }
        #endregion

        #region PresenceStatusChangedEvent
        public event EventHandler PresenceStatusChangedEvent
        {
            add
            {
                EventList.RemoveHandler(PresenceStatusChangedEventKey, value);
                EventList.AddHandler(PresenceStatusChangedEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(PresenceStatusChangedEventKey, value);
            }
        }

        public void OnPresenceStatusChangedEvent(PresenceStatusChangedEventArgs e)
        {
            if (EventList[PresenceStatusChangedEventKey] != null)
            {
                ((EventHandler)EventList[PresenceStatusChangedEventKey]).Invoke(this, e);
            }
        }
        #endregion

        #region ApplicationUnloadedEvent
        public event EventHandler ApplicationUnloadedEvent
        {
            add
            {
                EventList.RemoveHandler(ApplicationUnloadedEventKey, value);
                EventList.AddHandler(ApplicationUnloadedEventKey, value);
            }
            remove
            {
                EventList.RemoveHandler(ApplicationUnloadedEventKey, value);
            }
        }

        public void OnApplicationUnloadedEvent(EventArgs e)
        {
            if (EventList[ApplicationUnloadedEventKey] != null)
            {
                ((EventHandler)EventList[ApplicationUnloadedEventKey]).Invoke(this, e);
            }
        }
        #endregion
    }
}
